<template>
  <div>
    <el-table v-loading="loading" :data="onlCgformHeadRecordList" border tooltip-effect="darkTable">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('表名')" align="center" prop="tableName" min-width="180" show-overflow-tooltip />
      <el-table-column :label="$t('表版本')" align="center" prop="tableVersion" min-width="60" show-overflow-tooltip />
      <el-table-column :label="$t('发生时间')" align="center" prop="createTime" min-width="150">
        <template slot-scope="scope">
          <div>
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作人')" align="center" prop="nickName" min-width="150" />
      <el-table-column :label="$t('历史sql')" align="center" prop="historySql" min-width="700" show-overflow-tooltip>
        <template slot-scope="scope">
          <span style="text-align: left;  display: inline-block" class="pre" v-html="scope.row.historySql" />
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">{{ $t("取消") }}</el-button>
    </div>
  </div>
</template>

<script>
import { listOnlCgformHeadRecord } from '@/api/system/desform/onlineForm/onlCgformHead'
export default {
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 历史版本sql表格数据
          onlCgformHeadRecordList: [],
          // 弹出层标题
          title: '历史版本sql',
          // 是否显示弹出层
          formOpen: false,
          // 查询参数
          queryParams: {
              headId: undefined,
              interName: undefined,
              tableVersion: undefined,
              historySql: undefined,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {}
      }
  },
  created() {
      this.getList()
  },
  methods: {
    /** 查询历史版本sql列表 */
    getList(headId) {
        this.loading = true
        this.queryParams.headId = headId.id
        listOnlCgformHeadRecord(this.queryParams).then(response => {
            this.onlCgformHeadRecordList = response.rows
            this.total = response.total
            this.loading = false
        }).catch(() => {
            this.loading = false
        })
    },

    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            headId: undefined,
            interName: undefined,
            tableVersion: undefined,
            createBy: undefined,
            createTime: undefined,
            historySql: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    // 取消按钮
    cancel() {
      this.$parent.$parent.historySqlformOpen = false
      this.$parent.$parent.reset()
    }
  }
}
</script>
<style scoped>
  .pre {
    white-space: pre-line !important;
    word-break: break-all;
    word-wrap: break-word;
    text-align:left;
    line-height: 18px;
    cursor:pointer;
    font-size: 15px;
  }
</style>
